home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / arts / giomanager.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  3.3 KB  |  129 lines

  1.     /*
  2.  
  3.     Copyright (C) 2001 Stefan Westerfeld
  4.                        stefan@space.twc.de
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2 of the License, or (at your option) any later version.
  10.   
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.     Library General Public License for more details.
  15.    
  16.     You should have received a copy of the GNU Library General Public License
  17.     along with this library; see the file COPYING.LIB.  If not, write to
  18.     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19.     Boston, MA 02111-1307, USA.
  20.  
  21.     */
  22.  
  23. #ifndef ARTS_GIOMANAGER_H
  24. #define ARTS_GIOMANAGER_H
  25.  
  26. #include <glib.h>
  27. #include <iomanager.h>
  28. #include <list>
  29. #include <stack>
  30. #include <map>
  31. #include "arts_export.h"
  32. /*
  33.  * BC - Status (2002-03-08): GIOManager
  34.  *
  35.  * This class will be kept binary compatible (d ptr for extensions).
  36.  */
  37.  
  38. namespace Arts {
  39.  
  40. class GIOWatch;
  41. class GIOManagerPrivate;
  42. struct GIOManagerSource;
  43. class GIOTimeWatch;
  44. class GIOManagerBlocking;
  45.  
  46. /**
  47.  * GIOManager performs MCOP I/O inside the Glib event loop. This way, you will
  48.  * be able to receive requests and notifications inside Glib application. The
  49.  * usual way to set it up is:
  50.  *
  51.  * <pre>
  52.  * GMainLoop *main_loop = g_main_new(FALSE);  // as usual
  53.  *
  54.  * Arts::GIOManager iomanager;
  55.  * Arts::Dispatcher dispatcher(&iomanager);
  56.  *
  57.  * g_main_run(main_loop);                     // as usual
  58.  * </pre>
  59.  */
  60. class ARTS_EXPORT GIOManager : public IOManager {
  61. private:
  62.     GIOManagerPrivate *d;
  63.  
  64. protected:
  65.     std::list<GIOWatch *> fdList;
  66.     std::list<GIOTimeWatch *> timeList;
  67.     int level;
  68.     bool _blocking;
  69.     bool fileDescriptorsNeedRecheck;
  70.     GMainContext *context;
  71.     GIOManagerSource *source;
  72.     GIOManagerBlocking *gioManagerBlocking;
  73.  
  74. public:
  75.     GIOManager(GMainContext *context = 0);
  76.     ~GIOManager();
  77.  
  78.     void processOneEvent(bool blocking);
  79.     void run();
  80.     void terminate();
  81.     void watchFD(int fd, int types, IONotify *notify);
  82.     void remove(IONotify *notify, int types);
  83.     void addTimer(int milliseconds, TimeNotify *notify);
  84.     void removeTimer(TimeNotify *notify);
  85.  
  86.     /**
  87.      * This controls what GIOManager will do while waiting for the result
  88.      * of an MCOP request, the possibilities are:
  89.      *
  90.      * @li block until the request is completed (true)
  91.      * @li open a local event loop (false)
  92.      *
  93.      * It is much easier to write working and reliable code with blocking
  94.      * enabled, so this is the default. If you disable blocking, you have
  95.      * to deal with the fact that timers, user interaction and similar
  96.      * "unpredictable" things will possibly influence your code in all
  97.      * places where you make a remote MCOP call (which is quite often in
  98.      * MCOP applications).
  99.      */
  100.     void setBlocking(bool blocking);
  101.  
  102.     /* GSource stuff: */
  103.  
  104.     /**
  105.      *  - internal -
  106.      *
  107.      *  (implements the GSource prepare)
  108.      */
  109.     gboolean prepare(gint *timeout);
  110.  
  111.     /**
  112.      *  - internal -
  113.      *
  114.      *  (implements the GSource check)
  115.      */
  116.     gboolean check();
  117.  
  118.     /**
  119.      *  - internal -
  120.      *
  121.      *  (implements the GSource dispatch)
  122.      */
  123.     gboolean dispatch(GSourceFunc callback, gpointer user_data);
  124. };
  125.  
  126. }
  127.  
  128. #endif /* ARTS_GIOMANAGER_H */
  129.